package com.zy;

import io.netty.channel.Channel;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.EventLoopGroup;
import io.netty.handler.codec.serialization.ClassResolvers;
import io.netty.handler.codec.serialization.ObjectDecoder;
import io.netty.handler.codec.serialization.ObjectEncoder;

/**
 * @program: monitor147
 * @description:
 * @author: zy
 * @create: 2025-06-04 19:30
 */
public class MinotorServerInitializer extends ChannelInitializer<Channel> {

    private EventLoopGroup businessGroup;
    private final static int MAX_OBJECT_SIZE=1024*1024;

    public MinotorServerInitializer(EventLoopGroup businessGroup) {
        this.businessGroup = businessGroup;
    }

    @Override
    protected void initChannel(Channel ch) throws Exception {
        //在这里对channel进行实始化( 装配处理器 )
        ChannelPipeline pipeline=ch.pipeline();

        pipeline.addLast( new ObjectDecoder(MAX_OBJECT_SIZE, ClassResolvers.weakCachingConcurrentResolver(this.getClass().getClassLoader())));
        pipeline.addLast(   new ObjectEncoder() );
        pipeline.addLast(  businessGroup, new MonitorServerHandler()  );

    }
}
